#Boa:Frame:FrameCompany

import wx
from product import CDataCompany


def create(parent):
    return FrameCompany(parent)

[wxID_FRAMECOMPANY, wxID_FRAMECOMPANYBTNCANCEL, wxID_FRAMECOMPANYBTNSAVE, 
 wxID_FRAMECOMPANYPANELCOMPANY, wxID_FRAMECOMPANYTADDR, 
 wxID_FRAMECOMPANYTBRIEFNAME, wxID_FRAMECOMPANYTBUSINESS, 
 wxID_FRAMECOMPANYTCADDR, wxID_FRAMECOMPANYTCBRIEFNAME, 
 wxID_FRAMECOMPANYTCBUSINESS, wxID_FRAMECOMPANYTCNAME, 
 wxID_FRAMECOMPANYTCPHONE, wxID_FRAMECOMPANYTNAME, wxID_FRAMECOMPANYTPHONE, 
] = [wx.NewId() for _init_ctrls in range(14)]

class FrameCompany(wx.Frame):

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAMECOMPANY, name=u'FrameCompany',
              parent=prnt, pos=wx.Point(378, 279), size=wx.Size(481, 370),
              style=wx.DEFAULT_FRAME_STYLE, title=u'\u516c\u53f8\u8bbe\u7f6e')
        self.SetClientSize(wx.Size(473, 336))
        self.Center(wx.BOTH)

        self.panelCompany = wx.Panel(id=wxID_FRAMECOMPANYPANELCOMPANY,
              name=u'panelCompany', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(473, 336), style=wx.TAB_TRAVERSAL)

        self.tName = wx.StaticText(id=wxID_FRAMECOMPANYTNAME,
              label=u'\u516c\u53f8\u5168\u540d\uff1a', name=u'tName',
              parent=self.panelCompany, pos=wx.Point(32, 40), size=wx.Size(60,
              14), style=0)

        self.tcName = wx.TextCtrl(id=wxID_FRAMECOMPANYTCNAME, name=u'tcName',
              parent=self.panelCompany, pos=wx.Point(104, 32), size=wx.Size(320,
              22), style=0, value=u'')

        self.tBriefName = wx.StaticText(id=wxID_FRAMECOMPANYTBRIEFNAME,
              label=u'\u516c\u53f8\u7b80\u540d\uff1a', name=u'tBriefName',
              parent=self.panelCompany, pos=wx.Point(32, 80), size=wx.Size(60,
              14), style=0)

        self.tcBriefName = wx.TextCtrl(id=wxID_FRAMECOMPANYTCBRIEFNAME,
              name=u'tcBriefName', parent=self.panelCompany, pos=wx.Point(104,
              72), size=wx.Size(152, 22), style=0, value=u'')

        self.tPhone = wx.StaticText(id=wxID_FRAMECOMPANYTPHONE,
              label=u'\u8054\u7cfb\u7535\u8bdd\uff1a', name=u'tPhone',
              parent=self.panelCompany, pos=wx.Point(32, 120), size=wx.Size(60,
              14), style=0)

        self.tcPhone = wx.TextCtrl(id=wxID_FRAMECOMPANYTCPHONE, name=u'tcPhone',
              parent=self.panelCompany, pos=wx.Point(104, 112),
              size=wx.Size(320, 22), style=0, value=u'')

        self.tAddr = wx.StaticText(id=wxID_FRAMECOMPANYTADDR,
              label=u'\u8054\u7cfb\u5730\u5740\uff1a', name=u'tAddr',
              parent=self.panelCompany, pos=wx.Point(32, 160), size=wx.Size(60,
              14), style=0)

        self.tcAddr = wx.TextCtrl(id=wxID_FRAMECOMPANYTCADDR, name=u'tcAddr',
              parent=self.panelCompany, pos=wx.Point(104, 152),
              size=wx.Size(320, 22), style=0, value=u'')

        self.tBusiness = wx.StaticText(id=wxID_FRAMECOMPANYTBUSINESS,
              label=u'\u7ecf\u8425\u8303\u56f4\uff1a', name=u'tBusiness',
              parent=self.panelCompany, pos=wx.Point(32, 200), size=wx.Size(60,
              14), style=0)

        self.tcBusiness = wx.TextCtrl(id=wxID_FRAMECOMPANYTCBUSINESS,
              name=u'tcBusiness', parent=self.panelCompany, pos=wx.Point(104,
              200), size=wx.Size(320, 64),
              style=wx.TE_MULTILINE, value=u'')

        self.btnSave = wx.Button(id=wxID_FRAMECOMPANYBTNSAVE,
              label=u'\u4fdd\u5b58', name=u'btnSave', parent=self.panelCompany,
              pos=wx.Point(104, 288), size=wx.Size(75, 24), style=0)
        self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton,
              id=wxID_FRAMECOMPANYBTNSAVE)

        self.btnCancel = wx.Button(id=wxID_FRAMECOMPANYBTNCANCEL,
              label=u'\u53d6\u6d88', name=u'btnCancel',
              parent=self.panelCompany, pos=wx.Point(240, 288), size=wx.Size(75,
              24), style=0)
        self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancelButton,
              id=wxID_FRAMECOMPANYBTNCANCEL)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.myInit()
        
    def myInit(self):
        obj = CDataCompany.getCompanyInfo()
        
        self.tcName.SetValue(obj.getFieldVal(index = CDataCompany.COL_NAME))
        self.tcBriefName.SetValue(obj.getFieldVal(index = CDataCompany.COL_BRIEFNAME))
        self.tcPhone.SetValue(obj.getFieldVal(index = CDataCompany.COL_PHONE))
        self.tcAddr.SetValue(obj.getFieldVal(index = CDataCompany.COL_ADDR))
        self.tcBusiness.SetValue(obj.getFieldVal(index = CDataCompany.COL_BUSINESS))

    def OnBtnSaveButton(self, event):
        obj = CDataCompany.getCompanyInfo()
        
        data = {CDataCompany.COL_NAME:self.tcName.GetValue(),
                CDataCompany.COL_BRIEFNAME:self.tcBriefName.GetValue(),
                CDataCompany.COL_PHONE:self.tcPhone.GetValue(),
                CDataCompany.COL_ADDR:self.tcAddr.GetValue(),
                CDataCompany.COL_BUSINESS:self.tcBusiness.GetValue()}
                
        obj.setMulFieldVal(data)
        obj.update()
        self.Close()

    def OnBtnCancelButton(self, event):
        self.Close()
